<template>
	<view class="content">
    <div id="bg">
        <a :href="url"><img src="https://static-c42e43d7-e17d-4af5-aa92-446d416f272c.bspapp.com/static/0.gif" /></a>
    </div>
    <div class="create">
      <text @click.stop="gotoCreate()">去制作专属红包页</text>
    </div>
	</view>
</template>

<script>
  const getQueryVariable=(variable)=>{
     let query = window.location.search.substring(1);
     let vars = query.split("&");
     for (let i=0;i<vars.length;i++) {
       let pair = vars[i].split("=");
       if(pair[0] == variable){return pair[1].replace('/','');}
     }
     return '';
  }
	export default {
		data() {
			return {
        url:'https://ulink.alipay.com/?scheme=alipays%3A%2F%2Fplatformapi%2Fstartapp%3FsaId%3D10000007%26clientVersion%3D3.7.0.0718%26qrcode%3Dhttps%253A%252F%252Frender.alipay.com%252Fp%252Fc%252Falipay-red-qrcode%252Fshared.html%253Fchannel%253Dsearch_pwd%2526shareId%253D2088802770580317%2526token%253D196107930uwynr17jpetq14XV0%2526campStr%253DkPPFvOxaCL3f85TiKss2wsBZgIjulHjG%2526sign%253DqsiVOoa7TuphryWxyBdONXsMTnE3jiIBvWeUs3yV1sw%253D%2526chInfo%253DDingtalk%2526c_stype%253Dsearch_pwd'
			}
		},
		async onLoad({id}) {
      if(id){
        const {result:{data:[record]}}=await uniCloud.database().collection('alipay_redpacket').doc(id).get();
        console.log(record)
        if(record.alipay_user_id && record.alipay_token){
          this.url=this.genurl(record.alipay_user_id,record.alipay_token)
        }
      }else{
        const auth_code=getQueryVariable('auth_code')
        if(auth_code){
          this.gotoCreate(auth_code)
        }
      }
      // if (uni.getSystemInfoSync().platform == "android") {
      // }
      // window.location.href=this.url;
		},
		methods: {
      gotoCreate(auth_code){
        auth_code?uni.navigateTo({
          url:'/pages/create?auth_code='+(auth_code||'')
        }):uni.navigateTo({
          url:'/pages/create'
        })
      },
      genurl(userId,token){
        return `https://ulink.alipay.com/?scheme=alipays%3A%2F%2Fplatformapi%2Fstartapp%3FsaId%3D10000007%26clientVersion%3D3.7.0.0718%26qrcode%3Dhttps%253A%252F%252Frender.alipay.com%252Fp%252Fc%252Falipay-red-qrcode%252Fshared.html%253Fchannel%253Dsearch_pwd%2526shareId%253D${userId}%2526token%253D${token}%2526campStr%253DkPPFvOxaCL3f85TiKss2wsBZgIjulHjG%2526sign%253DqsiVOoa7TuphryWxyBdONXsMTnE3jiIBvWeUs3yV1sw%253D%2526chInfo%253DDingtalk%2526c_stype%253Dsearch_pwd` 
      }
		}
	}
</script>

<style scoped lang="scss">
	*{
      margin:0;
      padding:0;
  }
  #bg{
      width: 100%;
      height: 100%;
      position: fixed;
      top: 0;
  }
  #bg img{
      width: 100%;
      height: 100%;
  }
  
  .create{
    position: fixed;
    top:70%;
    z-index: 5;
    width: 100%;
    display: flex;
    justify-content: center;
    color: #ffebd3;
    font-size: 26rpx;
    text-decoration:underline;
    text-underline-offset: 4px;
  }
</style>
